package com.restfinder.common.component;

import org.springframework.validation.BindingResult;

import com.restfinder.common.component.utils.JsonSpringUtils;

public class JsonResponseFactory {

	public static JsonResponse createJsonResponse(BindingResult result){
		if(!result.hasErrors()){
			JsonResponse jr = new JsonResponse();
			jr.setStatus(JsonSpringUtils.JSON_STATUS_SUCCESS);
			return jr;
		}
		else{
			ValidationJsonResponse fjr = new ValidationJsonResponse();
			fjr.setStatus(JsonSpringUtils.JSON_STATUS_FAILURE);
			JsonSpringUtils.populateJsonByErrors(result, fjr);
			return fjr;
		}
	}
}
